package regex;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.htmlparser.NodeFilter;
import org.htmlparser.Parser;
import org.htmlparser.util.NodeList;
import org.htmlparser.util.ParserException;


public class RegexUtil {
	public static Pattern SAMPLE_ASSERT_REGEX_1 = Pattern
			.compile("\\b\\w+(?=ing\\b)");
	public static Pattern SAMPLE_ASSERT_REGEX_2 = Pattern.compile("(?:ing)");

	protected static String toPlainTextExcludeTag(String html) {
		String temp = html.replaceAll("(<([a-zA-Z0-9]+)([^>]*)>)(.*)(</\\2>)",
				"");
		return temp;
	}
	public static String pathParam(String path, String paramName, String paramValue) {
		return path.replaceAll("\\{" + paramName + "(:.*?)?\\}", paramValue);
	}

	public static void main(String[] args) {
		System.out.println("<img src='http://www.test.com/abc.jpg' />".replaceAll("src=(\"|')(/[\\w\\.]+)(\"|')", "src=$1http://test.com$2$3"));
//		String s = "// Now we are populating the above array with skuDropDownAttribName	skuDropdownSequenceArray[1] = \"1_dspColor\";" +
//				"availSku13.attrib_1_dspColor = \"White/Black\";availSku13.attrib_1_dspColor = \"White/Black\";availSku13.attrib_1_dspColor = \"White/Black\";";
//		
//		List<Color> cs = new ArrayList<Color>(0);
//		Pattern p = Pattern.compile("(?<=dspColor \\= )\"([\\w/]+)\"");
//		Matcher m = p.matcher(s);
//		while(m.find()) {
//			Color c = new Color(m.group(1));
//			if(!cs.contains(c)) {
//				cs.add(c);
//			}
//		}
//		System.out.println(Integer.MAX_VALUE);
//		
//		 Matcher m = SAMPLE_ASSERT_REGEX_1.matcher("i am doing home");
//		 if (m.find()) {
//		 System.out.println(m.group());
//		 }
//		 String str = "happymaster@163.com";
		// String regex = "(?x)\\w+ #username\n@\\S+ #hostname";
		// Pattern p = Pattern.compile(regex);
		// Matcher m = p.matcher(str);
		// if(m.find()){
		// System.out.println(str + " can match:" + regex);
		// System.out.println(m.group());
		//
		// }else{
		// System.out.println(str + " can not match:" + regex);
		// }
		// Matcher m =
		// Pattern.compile("s/\bJeffs\b/Jeff's/g").matcher("see Jeffs book");
		// if(m.find()) {
		// System.out.println(m.group());
		// }
		// StringBuilder text = new
		// StringBuilder("It's SO veRy RUDE to shout!");
		// Matcher m = Pattern.compile("\\b[\\p{Lu}\\p{Lt}]+\\b").matcher(text);
		// while (m.find())
		// text.replace(m.start(), m.end(), m.group().toLowerCase());
		// System.out.println(text);
		// String url = "http://regex.info/bl og";
		// String regex = "(?x) ^(https?):// ([^/:]+) (?:(\\d+))?";
		// Matcher m = Pattern.compile(regex).matcher(url);
		//
		// if (m.find())
		// {
		// System.out.print(
		// "Overall  [" + m.group() + "]" +
		// " (from " + m.start() + " to " + m.end() + ")\n" +
		// "Protocol [" + m.group(1) + "]" +
		// " (from " + m.start(1) + " to " + m.end(1) + ")\n" +
		// "Hostname [" + m.group(2) + "]" +
		// " (from " + m.start(2) + " to " + m.end(2) + ")\n"
		// );
		// // Group #3 might not have participated, so we must be careful here
		// if (m.group(3) == null)
		// System.out.println("No port; default of '80' is assumed");
		// else {
		// System.out.print("Port is [" + m.group(3) + "] " +
		// "(from " + m.start(3) + " to " + m.end(3) + ")\n");
		// }
		// }

	}
	
	public static boolean isCaptailized(String word) {
		return Pattern.compile("[A-Z][a-zA-Z]*").matcher(word).find();
	}

	private static void extractPriceRange() {
		Pattern p = Pattern.compile("(?:\\$[\\d+.]+ - )?(\\$[\\d.]+)");
		Matcher m = p.matcher("$31.49");
		if (m.find()) {
			System.out.println(m.group(1));
		}
	}

	public static void assertsRegex() {
		Matcher m = Pattern.compile("\\b\\w+(?=ing\\b)").matcher(
				"i am doing homework");
		if (m.find()) {
			System.out.println(m.group());
		}
	}

	public static void stringUpd(String str) {
		str = str.replace("j", "l");
		System.out.println(str);
	}

	public static void stringUpd(Integer str) {
		str = str + 1;
		System.out.println(str);
	}

	public static void stringBufferUpd(StringBuffer bf) {
		bf.append("c");
		System.out.println(bf);
	}

	public class UnicodeProperty {
	}
}
